<?php

namespace app\admin\model;

use think\Model;


class Order extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'order_status_text',
        'pay_createtime_text',
        'switch_text'
    ];
    

    
    public function getOrderStatusList()
    {
        return ['notpay' => __('Order_status notpay'), 'paid' => __('Order_status paid'), 'unusual' => __('Order_status unusual'), 'refund' => __('Order_status refund')];
    }

    public function getSwitchList()
    {
        return ['0' => __('Switch 0'), '1' => __('Switch 1')];
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_createtime']) ? $data['pay_createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSwitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['switch']) ? $data['switch'] : '');
        $list = $this->getSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPayCreatetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
